home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 310_02 / semaphor.st < prev    next >
Text File  |  1990-04-18  |  542b  |  25 lines

  1. Class  Semaphore :List
  2. | excessSignals |
  3.  
  4. [  new
  5.     excessSignals <- 0
  6.  
  7. |  new: aNumber
  8.     excessSignals <- aNumber
  9.  
  10. |  signal
  11.     <StartAtomic>.    "start atomic action"
  12.     (self isEmpty)
  13.       ifTrue: [excessSignals <- excessSignals + 1]
  14.       ifFalse: [self removeFirst unblock].
  15.     <EndAtomic>        "end atomic action"
  16.  
  17. |  wait
  18.     <StartAtomic>.    "start atomic actions"
  19.     (excessSignals = 0)
  20.       ifTrue: [self addLast: selfProcess.
  21.            selfProcess block]
  22.       ifFalse: [excessSignals <- excessSignals - 1].
  23.     <EndAtomic>        "end atomic actions"
  24. ]
  25.